package cn.com.headfree.expert.service.impl;

import cn.com.headfree.entity.*;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.expert.dao.IDeclareExpertDao;
import cn.com.headfree.expert.service.IDeclareExpertService;
import cn.com.headfree.recordlog.service.IRecordLogService;
import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.util.IdGen;
import com.gta.edu.sdk.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: TODO
 * @Author wcSun
 * @Date 2022/6/28
 **/
@Service("declareExpertService")
public class DeclareExpertServiceImpl implements IDeclareExpertService {

    @Autowired
    private IDeclareExpertDao declareExpertDao;

    @Autowired
    private IRecordLogService recordLogService;

    @Override
    public void saveDeclareExpertInfo(TDeclareExpertInfo declareExpertInfo) {
        declareExpertInfo.setCreaterId(declareExpertInfo.getErpNo());
        declareExpertInfo.setCreaterName(declareExpertInfo.getUserName());
        declareExpertInfo.setUpdaterId(declareExpertInfo.getErpNo());
        declareExpertInfo.setUpdaterName(declareExpertInfo.getUserName());
        declareExpertInfo.setCreateTime(new Date());
        declareExpertInfo.setUpdateTime(new Date());
        declareExpertInfo.setDelSign(0);
        declareExpertInfo.setAuditStatus("0");//待审核

        if(StringUtils.isEmpty(declareExpertInfo.getId())){
            declareExpertInfo.setId(IdGen.uuid());
        }
        declareExpertDao.saveDeclareExpertInfo(declareExpertInfo);
    }

    @Override
    public List<TDeclareExpertInfo> judge(TDeclareExpertInfo tDeclareExpertInfo) {
        return declareExpertDao.judge(tDeclareExpertInfo);
    }

    @Override
    public void getPageDeclareExpertInfo(Page<TDeclareExpertInfo> page, String year, User user) {
        declareExpertDao.getPageTDeclareExpertInfo(page, year, user);
    }

    @Override
    public void auditAgreeInfo(String declareExpertId, User user) {
        //先修改专家人才申报表状态，由待审核变更为同意
        declareExpertDao.updateDeclareExpertState(declareExpertId,"1",null);
        //日志
        TRecordOptLog log = new TRecordOptLog();
        log.setOptType("6");
        log.setOptContent(user.getName()+"核实并同意了该人才评定申请");
        log.setCurrentRecordId(declareExpertId);
        log.setRecordId(declareExpertId);
        recordLogService.save(user,log);
    }

    @Override
    public void auditRejectInfo(String declareExpertId, User user,String auditOpt) {
        //先修改薪档申报状态--由待审核变更为不同意
        declareExpertDao.updateDeclareExpertState(declareExpertId,"2",auditOpt);
        //删除积分信息
//        declareExpertDao.deletePersonYearPointDetailInfo(declareExpertId);
        //日志
        TRecordOptLog log = new TRecordOptLog();
        log.setOptType("8");
        if(StringUtil.isNullOrEmpty(auditOpt)){
            log.setOptContent(user.getName()+"驳回了该人才评定申请");
        }else{
            log.setOptContent(user.getName()+"驳回了该人才评定申请，驳回理由是："+auditOpt);
        }
        log.setCurrentRecordId(declareExpertId);
        log.setRecordId(declareExpertId);
        recordLogService.save(user,log);
    }

    @Override
    public void getPageDeclareExpertInfoQuery(Page<TDeclareExpertInfo> page, String baseOrgId,  String deptId,String userName, String erpNo, Integer year, String auditStatus){
        declareExpertDao.getPageDeclareExpertInfoQuery(page,baseOrgId,deptId,userName,erpNo,year,auditStatus);
    }

    @Override
    public List<TDeclareExpertInfo> getDeclareExpertInfoQuery(String baseOrgId, String deptId,String userName, String erpNo, Integer year, String auditStatus){
        return declareExpertDao.getListSalaryInfoQuery(baseOrgId, deptId,userName,erpNo,year,auditStatus);
    }

    @Override
    public TDeclareExpertInfo getTDeclareExpertInfoById(String id) {
        return declareExpertDao.getTDeclareExpertInfoById(id);
    }
}
